#include <iostream>
#include "euler/imath.hpp"
#include "euler.h"

BEGIN_PROBLEM(207, solve_problem_207)
	PROBLEM_TITLE("Integer partition equations")
	PROBLEM_ANSWER("44043947822")
	PROBLEM_DIFFICULTY(1)
	PROBLEM_FUN_LEVEL(2)
	PROBLEM_TIME_COMPLEXITY("ln(q)")
	PROBLEM_SPACE_COMPLEXITY("1")
END_PROBLEM()

static void solve_problem_207()
{
	int q = 12345;

	// Iterative method.
	int n = 2;
	while (n - 1 <= q * euler::ilog(n, 2))
		n = q * euler::ilog(n, 2) + 2;

	std::cout << (long long)n*(n-1) << std::endl;
}
